﻿using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;
using System.Windows.Forms;
using QRCoder;
using WLSEND.Common;
using System.Drawing.Printing;
using System.Drawing.Text;

namespace printtest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Button1_Click(object sender, EventArgs e)
        {
            Print("11111");
        }

        private void Print(string _OrderID)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("销售小票\n");
            sb.Append("谢谢惠顾，欢迎下次光临\n");
            BarcodeHelper bh = new BarcodeHelper();
            BarcodeHelper.Generate1("sh",40,50);
            pictureBox1.Image = BarcodeHelper.Generate1("test0909", 200, 200);
            PrintHelper ph = new PrintHelper();
            ph.Print(sb.ToString());
        }
        PrintDocument pd = new PrintDocument();
        SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);
        Font font = new Font("Arial", 22);
        private void Button2_Click(object sender, EventArgs e)
        {
            // PrintDocument pd = new PrintDocument();
            //SolidBrush brush = new SolidBrush(System.Drawing.Color.Black);
            //Font font = new Font("Arial", 22);
            pd.PrintPage += PicturePrintDocument_PrintPage;
            pd.PrinterSettings.PrinterName= pd.DefaultPageSettings.PrinterSettings.PrinterName;
            StringBuilder sb = new StringBuilder();
            sb.Append("销售小票\n");
            PrintHelper ph = new PrintHelper();
            ph.Print(sb.ToString());
            pd.Print();
        }


        private void PicturePrintDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(BarcodeHelper.Generate1("http://weixin.qq.com/r/BS3H3_fEkbruraO893gX", 120, 120), 30, 0);  //img大小
            e.Graphics.DrawString("test09", font, brush, 600, 600); //绘制字符串
            e.HasMorePages = false;
        }
        
        //string asset = "test0909";
        //    public static Bitmap CreateQRCode(string asset)
        //{
        //    EncodingOptions options = new QrCodeEncodingOptions
        //    {
        //        DisableECI = true,
        //        CharacterSet = "UTF-8",
        //        Width = 120,
        //        Height = 120
        //    };
        //    BarcodeWriter writer = new BarcodeWriter();
        //    writer.Format = BarcodeFormat.QR_CODE;
        //    writer.Options = options;
        //    return writer.Write(asset);
        //}
    }
}